package com.wxyzz.canteenadmin.vip.controller;


import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.vip.entity.member.dto.MemberAddDTO;
import com.wxyzz.canteenadmin.vip.entity.member.dto.MemberEditDTO;
import com.wxyzz.canteenadmin.vip.entity.member.dto.MemberQueryDTO;
import com.wxyzz.canteenadmin.vip.entity.member.vo.MemberListVO;
import com.wxyzz.canteenadmin.vip.entity.member.vo.MemberVO;
import com.wxyzz.canteenadmin.vip.service.IMemberService;
import com.wxyzz.canteencommon.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyz
 * @since 2024-10-10
 */
@RestController
@RequestMapping("/member")
//会员操作
public class MemberController {

    @Autowired
    private IMemberService iMemberService;
    @RequestMapping("/list")
    public R list(MemberQueryDTO memberQueryDTO){
        PageInfo<MemberListVO> getlist = iMemberService.list(memberQueryDTO);
        return R.ok(getlist);
    }

    @RequestMapping("/add")
    public R add(@RequestBody @Validated MemberAddDTO memberAddDTO){
        iMemberService.add(memberAddDTO);
        return R.ok();
    }

    @RequestMapping("/getdetailbyid")
    public R getdetail(Integer memberId){
       MemberVO memberVO=  iMemberService.getdetail(memberId);
       return R.ok(memberVO);
    }
    @RequestMapping("/update")
    public R update(@RequestBody @Validated MemberEditDTO memberEditDTO){
        Integer ret = iMemberService.update(memberEditDTO);
        return ret == 1 ? R.ok(): R.fail();

    }
    @RequestMapping("/delete")
    public R delete(Integer memberId){
        Integer ret = iMemberService.delete(memberId);
        return ret == 1 ? R.ok(): R.fail();
    }



}
